package com.cheyun.netsalev3.view

import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.adapter.MyAdapter
import com.cheyun.netsalev3.bean.records.Follow
import com.cheyun.netsalev3.databinding.ActivityFollowUpListBinding
import com.cheyun.netsalev3.utils.BaseActivity
import com.cheyun.netsalev3.utils.InjectorUtils
import com.cheyun.netsalev3.viewmodel.FollowUpListActivityViewModel

class FollowUpListActivity : BaseActivity<ActivityFollowUpListBinding>() {
    private lateinit var adapter: MyAdapter

    override fun initViewModel(): ViewModel? {

        var list = ArrayList<Follow>()
        intent.getSerializableExtra("data")?.apply {
            var data = this as ArrayList<Follow>
            list.addAll(data)
        }

        var factory = InjectorUtils.getFollowUpViewModelFactory(list)
        return ViewModelProviders.of(this, factory).get(FollowUpListActivityViewModel::class.java)
    }

    override fun initData() {
        binding.viewModel?.datalist?.observe(this, Observer { list ->
            adapter.submitList(list)
        })
    }

    override fun initContentView(): Int {
        return R.layout.activity_follow_up_list
    }


    override fun initView() {
        adapter = MyAdapter(R.layout.follow_up_list_item, binding.viewModel)
        binding.recyclerView.adapter = adapter
    }

}
